package org.airline.action;

import java.util.List;

import javax.annotation.Resource;

import org.airline.common.IModuleName;
import org.airline.entity.Flight;
import org.airline.entity.PageBean;
import org.airline.service.FlightInfoService;
import org.springframework.stereotype.Component;

@Component("FlightAction")
@SuppressWarnings("all")
public class FlightAction extends SuperAction{
	
	private int id;
	private int page = 1;
	private int pageSize = 10;
	private String keyWord;
	private Flight flight;
	private String forwardURL;
	private PageBean pageBean;
	private IModuleName iModuleName;
	private List<Flight> flightList;
	private FlightInfoService FlightInfoService;
	
	//  添加航班信息
	public String inserFlight()throws Exception{
		try{
			this.FlightInfoService.insertFlight(flight);
		}catch(Exception e){
			
			e.printStackTrace();
		}
		this.forwardURL = "FlightInfo!getAllFlightInfo";
		return "flightInfo";
	}
	
	// 后台获取所有航班信息
	public String getAllFlightInfo() throws Exception {
		try {
			pageBean = FlightInfoService.queryForPage(pageSize, page);
		} catch (RuntimeException e) {
			e.printStackTrace();
		}
		forwardURL = "/admin/showAllFlight.jsp";
		return "success";
	}
	
	// 通过ID删除航班信息
	public String deleteFlightById() throws Exception {
		try {
			this.FlightInfoService.deleteFlightById(id);
		} catch (RuntimeException e) {
			e.printStackTrace();
		}
		forwardURL = "FlightInfo!getAllFlightInfo";
		return "flightInfo";
	}
	
	// 更新航班信息
	public String updateFlightInfo() throws Exception {
		try {
			this.FlightInfoService.updateFlight(flight);
		} catch (RuntimeException e) {
			
			e.printStackTrace();
		}
		forwardURL = "FlightInfo!getAllFlightInfo";
		return "flightInfo";
	}
	
	// 根据关键字分页查询航班信息
	public String getFlightsByKeyWords() throws Exception {
		try {
			pageBean = FlightInfoService.queryForPageByKeyWords(keyWord, pageSize, page);
		} catch (Exception e) {
			super.logFailureString(iModuleName.GET, iModuleName.GET,
					"根据关键字分页查询航班信息失败", e);
			e.printStackTrace();
		}
		super.logSuccessString(iModuleName.GET, iModuleName.GET,
				"根据关键字分页查询航班信息成功");
		forwardURL = "/admin/showAllFlight.jsp";
		return SUCCESS;
	}
	
	// 通过ID获取航班信息
	public String getAllFlightById() throws Exception {
		try {
			this.flight = this.FlightInfoService.getAllFlightById(id);
		} catch (RuntimeException e) {
			
			e.printStackTrace();
		}
		forwardURL = "/admin/updateFlightInfo.jsp";
		return "success";
	}

	// 前台获取所有航班信息
	public String getFlightInfo() throws Exception {
		try{
			pageBean = FlightInfoService.queryForPage(pageSize, page);
		} catch(Exception e) {
			e.printStackTrace();
		}
		forwardURL = "/jsp/showFlightInfo.jsp";
		return SUCCESS;
	}
	
	public Flight getFlight() {
		return flight;
	}
	public void setFlight(Flight flight) {
		this.flight = flight;
	}
	public FlightInfoService getFlightInfoService() {
		return FlightInfoService;
	}
	@Resource(name="FlightInfoService")
	public void setFlightInfoService(FlightInfoService flightInfoService) {
		this.FlightInfoService = flightInfoService;
	}

	public String getForwardURL() {
		return forwardURL;
	}

	public void setForwardURL(String forwardURL) {
		this.forwardURL = forwardURL;
	}

	public List<Flight> getFlightList() {
		return flightList;
	}

	public void setFlightList(List<Flight> flightList) {
		this.flightList = flightList;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public PageBean getPageBean() {
		return pageBean;
	}

	public void setPageBean(PageBean pageBean) {
		this.pageBean = pageBean;
	}

	public String getKeyWord() {
		return keyWord;
	}

	public void setKeyWord(String keyWord) {
		this.keyWord = keyWord;
	}

	public IModuleName getiModuleName() {
		return iModuleName;
	}

	public void setiModuleName(IModuleName iModuleName) {
		this.iModuleName = iModuleName;
	}

}
